<template>
  <div>
    <card>
      <div>
        <Button type="primary" @click="backBtn">返回</Button>&nbsp;
        <Button type="primary" @click="submitBtn">提交</Button>&nbsp;
        <Button type="primary" @click="backPartnersBtn">退回</Button>&nbsp;
        <Button type="primary" @click="refreshGpsInfo">刷新GPS信息</Button>&nbsp;
        <Button type="primary" @click="showImage">影像信息</Button>
      </div>
    </card>
    <div>
      <card>
        <Tabs value="name1" type="card" :animated="true">
          <TabPane label="GPS信息" name="name1">
            <gpsAuditDetail ref="gpsAuditDetail" :detailParams="detailParams" />
          </TabPane>
          <TabPane label="合同信息" name="name2" >
            <loan-Audit-Detail ref="loanAuditDetail" :detailParams="detailParams"></loan-Audit-Detail>
          </TabPane>
        </Tabs>
      </card>
    </div>

  <div v-if="isShowModel">
                <filePreview :showFileList="showFileList" :path="path"  @close-img-model="closeImgModel"></filePreview>
            </div>
  </div>
</template>
<script>
import gpsAuditDetail from '../loan-gps-manage/loanGpsAuditDetail';
import loanAuditDetail from '../loan-audit/loanAuditDetail';
import filePreview from "../../../../../basic/pages/image/upload-file/filePreview.vue";
import {
  gpsManageSubmit,
  backPartnersSubmit,
  getAllOrderInfoByAppCode,
  getGpsImage
} from '_p/afs-core-business/api/afs-case/loan-gps-manage/loanGpsManage'
export default {
  name: 'gpsAudit',
  components: {
    gpsAuditDetail,
    loanAuditDetail,
    filePreview
  },
  props: {
    detailParams: {},
  },
  data() {
    return {
      isShowModel: false,//是否展示model
      showFileList: [], //预览需要展示的部分
      path:"case",
      checkedList: [],
      checkboxList: [],
    }
  },
  methods: {
    backBtn() {
      this.$emit('backTo')
    },
    submitBtn() {
      gpsManageSubmit(this.detailParams).then((res) => {
        if (res.code === '0000') {
          this.$Message.success(res.msg)
          this.backBtn()
        }
      })
    },
    backPartnersBtn() {
      backPartnersSubmit(this.detailParams).then((res) => {
        if (res.code === '0000') {
          this.$Message.success(res.msg)
          this.backBtn()
        }
      })
    },
    refreshGpsInfo() {
      getAllOrderInfoByAppCode(this.detailParams).then((res) => {
        if (res.code === '0000') {
          this.$Message.success(res.msg)
          this.$emit('changeLoanDetail',res.data)
          this.$refs.gpsAuditDetail.refresh()
        }
      })
    },
    // 展示图片
    showImage() {
      console.log("查看图片"+this.detailParams);
      this.collectChecked();

            
    },
    // 关闭图片
    closeImgModel(value) {
            this.isShowModel = value;
            // 关闭不需要刷新文件
            // let selectedNode = this.$refs.tree.getSelectedNodes()[0];
            // this.showFile(selectedNode);
    },
    collectChecked() {
            console.log(this.checkedList, "collectChecked _this.checkedList");
            let checkedFiles = [];
            let fileList =[];
            let dataList = [];
            getGpsImage(this.detailParams).then((res) => {
              if (res.code === '0000') {
                 fileList =res.data;
                 if(fileList.length>0){

                  fileList.forEach(async (file, index) => {
                            file.fileType = file.fileType.toLowerCase();
                            // if (file.fileStatus !== "standard") {
                            //     this.isUploadShow = true;
                            // }
                            if (file.fileType === "jpg" || file.fileType === 'png' || file.fileType === 'jpg' || file.fileType === 'jpeg') {
                                // let url= await getBlob(file.fileId,file.fileName);
                                let url = `${_AFS_PROJECT_CONFIG.apiUri}/${this.path}/upload/getBlob/${file.fileType}/${file.fileId}`;
                                dataList.push(Object.assign({}, file, {thumSrc: url, imgSrc: url}))
                            } else if (file.fileType === "pdf") {
                                let url = `${_AFS_PROJECT_CONFIG.apiUri}/${this.path}/upload/getBlob/${file.fileType}/${file.fileId}`;
                                dataList.push(Object.assign({}, file, {thumSrc: pdfImg, imgSrc: url}))
                            } else if (file.fileType === "docx" || file.fileType === "doc") {
                                dataList.push(Object.assign({}, file, {thumSrc: wordImg, imgSrc: ""}))
                            }
                        })
                    console.log('fileList', dataList);
                    this.checkboxList = dataList;
                    for(var i=0;i<dataList.length;i++){
                      let item=dataList[i];
                      console.log(item)
                      let type = item.fileType;
                          if (type.indexOf("png,jpg,jpeg,gif,bmp")) {
                            console.log("1111111111")
                              type = "img";
                          }
                          checkedFiles.push(Object.assign({},item,{type,imageFlow:''}));
                    }
                    console.log(checkedFiles)
                    if (checkedFiles.length > 0) {
                      this.showFileList = checkedFiles;
                      this.isShowModel = true;
                      this.$emit("open-img-model")
                  } else {
                      this.$Message.warning('暂无图片');
                  }
                }
              }
            })
            console.log("222222"+checkedFiles)
            
        },
  },
}
</script>
